package com.seocoo.worker.friend;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.seocoo.worker.R;
import com.seocoo.worker.base.http.BasePageRsp;
import com.seocoo.worker.base.refresh.SwipeRefreshMoreLayout;
import com.seocoo.worker.friend.adapter.FriendAppraiseAdapter;
import com.seocoo.worker.friend.module.FriendAppraiseModule;
import com.seocoo.worker.friend.req.ReqFriendAppraise;
import com.seocoo.worker.friend.rsp.RspFriendAppraise;
import com.sfh.lib.mvvm.LiveDataMatch;
import com.sfh.lib.ui.MVVMFragment;

/**
 * author : Ssp
 * date   : 2020/2/23 16:25
 * desc   : 我的评价
 */
public class FriendAppraiseFragment extends MVVMFragment implements BaseQuickAdapter.OnItemClickListener, SwipeRefreshMoreLayout.OnLoadingListener {

    private FriendAppraiseAdapter mAdapter = new FriendAppraiseAdapter();
    private SwipeRefreshMoreLayout swipe_refresh_more_layout;
    //评价类型 1用户评价 2 工友评价
    private String appraiseType;

    public static FriendAppraiseFragment newInstance(String orderType) {
        FriendAppraiseFragment fragment = new FriendAppraiseFragment();
        Bundle bundle = new Bundle();
        bundle.putString("appraiseType", orderType);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public int getLayout() {
        return R.layout.friend_appraise_fragment;
    }

    @Override
    public void initData(View view) {
        swipe_refresh_more_layout = view.findViewById(R.id.swipe_refresh_more_layout);
        appraiseType = getArguments().getString("appraiseType");
        swipe_refresh_more_layout.setAdapter(mAdapter, true);
        swipe_refresh_more_layout.setOnItemClickListener(this);
        swipe_refresh_more_layout.setOnLoadingListener(this);
        swipe_refresh_more_layout.addItemDecorationSize(2);
        reFreshData();
    }

    public void reFreshData() {
        swipe_refresh_more_layout.onAutoRefresh();
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

    }

    @Override
    public void onLoadMoreUI(int nowPage) {
        getViewModel(FriendAppraiseModule.class).query(new ReqFriendAppraise(nowPage, appraiseType));
    }

    @LiveDataMatch
    public void onSuccess(BasePageRsp<RspFriendAppraise> data) {
        swipe_refresh_more_layout.onRefreshCompale(data);
    }

}
